package com.ejlchina.keno



fun getThreeHitInAllLinesCount(sampleListShort: List<List<Int>>, checkList: List<Int>): Int {
    var threeHitCount = 0
    for (item in sampleListShort) {
        if (intersectCount(item,checkList) == 3) {
            threeHitCount++
        }
    }
    return threeHitCount
}


fun getContinuousThreeSame(sampleList: List<List<Int>>, checkList: List<Int>): Int {
    return continuousThreeSameCount(sampleList, checkList)
}


fun continuousThreeSameCount(sampleList: List<List<Int>>, resultList: List<Int>, needLog: Boolean = false): Int {
    var continuousThreeSameCount = 0
    val subCandidateList1 = resultList.subList(0, 3)
    val subCandidateList2 = resultList.subList(1, 4)
    val subCandidateList3 = resultList.subList(2, 5)
    val pageSampleList = sampleList.divideListToPageList()
    for ((pageIndex, pageItem) in pageSampleList.withIndex()) {
        for ((lineIndex,lineItem) in pageItem.withIndex()) {
            val isSameWith03 =
                (lineItem.subList(0, 3) - subCandidateList1.toSet()).isEmpty() ||
                        (lineItem.subList(1, 4) - subCandidateList1.toSet()).isEmpty() ||
                        (lineItem.subList(2, 5) - subCandidateList1.toSet()).isEmpty() ||
                        (lineItem.subList(0, 3) - subCandidateList2.toSet()).isEmpty() ||
                        (lineItem.subList(1, 4) - subCandidateList2.toSet()).isEmpty() ||
                        (lineItem.subList(2, 5) - subCandidateList2.toSet()).isEmpty() ||
                        (lineItem.subList(0, 3) - subCandidateList3.toSet()).isEmpty() ||
                        (lineItem.subList(1, 4) - subCandidateList3.toSet()).isEmpty() ||
                        (lineItem.subList(2, 5) - subCandidateList3.toSet()).isEmpty()
            if (isSameWith03) {
                continuousThreeSameCount++
                if (needLog) {
                    println("ContinuousThreeSame pageIndex:${pageIndex + 1},lineIndex:${lineIndex + 1},resultList->$resultList")
                }
            }
        }
    }
    return continuousThreeSameCount
}



fun checkEveryNumberNoMoreThan35(sourceList: List<List<Int>>){
    for (lineItem in sourceList) {
        for (item in lineItem) {
            if (item > 35) println(item)
        }
    }
}

/**
 * 测试样本的每页是否没有重复数字(检验用)
 */
fun checkEveryPageNoRepeat(sourceList: List<List<Int>>) {
    val pageList = sourceList.shortToLongList()
    for ((index,pageItem) in pageList.withIndex()) {
        if (pageItem.distinct().size < 25) println(index)
    }
}
